/************************************************************
* Copyright (C), 2013, Yixun.
* 模块名    :
* 实现功能  :
* 备注      :

* 修改记录  :
* 日 期             修改人              修改内容
  2013.10.15         blucelu              创建
***********************************************************/
#include <stdlib.h>
#include <sstream>
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>

#include "app_platform/cntl_info.h"
#include "app_platform/res_factory.h"

#include "c2cplatform/component/dal/dal_set.h"
#include "c2cent/storage/resultset.h"

#include "c2cplatform/library/xml/xml_cfg_loader.h"
#include "c2cplatform/library/string/string_helper.h"
#include "libc2c/c2c_errno_define.h"

#include "c2cent/library/log/CWWLog2.h"
#include "erp/comm/erp_errno_define.h"
#include "erp/comm/erp_macro_define.h"

#include "account_db_operator.h"
#include "c2cent/dao/idmaker/idmakerdao_stub4web_allinone.h"

using namespace c2cent::library::wwlog;
using namespace c2cent::storage;
using namespace c2cplatform::component::dal;
using namespace c2cplatform::library::string;

using namespace erp::comm;
using namespace erp::account::db;
using namespace erp::account::ddo;

#define DB_ROLE_NAME_ACCOUNT                 "erp_yun_account"

#define TABLE_NAME_BUSINESSUNITS            "T_BusinessUnits_"

//db初始化
int CAccountDBOperator::InitDB(IUserDefineCntl* pCntl)
{
    if(CDAL_SET->Initialize() != 0)
    {
        C2C_WW_LOG_ERR(-1, "CDAL_SET->Initialize() fail. %s", CDAL_SET->getLastErrMsg());
        return -1;
    }
    C2C_WW_LOG("CDAL_SET->Initialize Ok");

    return 0;
}

/**
*
*   更新【新增和修改】往来单位
*
*/
int32_t CAccountDBOperator::ModifyBusinessUnits(
           const CCntlInfo& rCntlInfo,
           const std::string& strMachineKey,
           const std::string& strSource,
           uint32_t dwSceneId,
           uint32_t dwOption,
           const erp::account::ddo::CBusinessUnitsDdo& oBusinessUnitsDdo,
           const std::string& strInReserve,
           std::string& strErrmsg,
           uint64_t& ddwSysNo,
           std::string& strOutReserve
          )
{
    int32_t iRetCode = 0;
    int32_t dwKeyId = rCntlInfo.getOperatorUin();
    uint16_t wUseSetId = 0;
    std::stringstream ssSql;

    C2C_WW_LOG("CAccountDBOperator %s cmdID:%u dwEmployeeId:%u sDbRoleName:%s sTableBaseName:%s wUseSetId:%u", __FUNCTION__,
            rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS, wUseSetId);

    CONNECT_WITH_DALSET(m_oStorage, rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS, wUseSetId,
            rCntlInfo, strMachineKey, strSource, dwSceneId);

    // SQL INSERT
    SQL_INSERT_TABLE(ssSql, wUseSetId, dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS);
    // INT VALUE
    SQL_SET_INT_FIELD_VALUE(ssSql, BusinessUnitsSysNo, ddwSysNo);
    SQL_SET_INT_FIELD_VALUE(ssSql, CreatorSysNo, rCntlInfo.getOperatorUid());
    SQL_SET_INT_FIELD_VALUE(ssSql, ModifierSysNo, rCntlInfo.getOperatorUid());
    // INT OBJECT
    SQL_SET_INT_FIELD(ssSql, BusinessUnitsType, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, CreateDate, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, PayDueTime, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, DiscountRate, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, PrePriceLevel, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, ParentSysNo, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, ClearingContactUnitSysNo, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, AreaSysNo, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, StaffSysNo, oBusinessUnitsDdo);
    SQL_SET_INT_FIELD(ssSql, BusinessUnitsStatus, oBusinessUnitsDdo);

    // STRING
    SQL_SET_STRING_FIELD(ssSql, BusinessUnitsID, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, FullName, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Name, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, PyCode, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Telephone, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Fax, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Email, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, NetAddress, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, ZipCode, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Address, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, BankAccount, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, BankAccountName, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, BankName, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, Comment, oBusinessUnitsDdo, m_oStorage);
    SQL_SET_STRING_FIELD(ssSql, ContactSysNos, oBusinessUnitsDdo, m_oStorage);

    // Property
    SQL_SET_PROPERTY_FIELD(ssSql, BusinessUnitsProperty, oBusinessUnitsDdo);

    // NOW
    SQL_SET_TIME_FIELD_NOW(ssSql, RowCreatDate);
    SQL_SET_TIME_FIELD_NOW(ssSql, RowModifyDate);

    // ON DEPLICATE KEY UPDATE
    SQL_DUPLICATE_UPDATE(ssSql);

    // Update
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, ModifierSysNo, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BusinessUnitsType, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, CreateDate, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, PayDueTime, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, DiscountRate, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, PrePriceLevel, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, ParentSysNo, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, ClearingContactUnitSysNo, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, AreaSysNo, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, StaffSysNo, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BusinessUnitsStatus, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BusinessUnitsID, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, FullName, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Name, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, PyCode, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Telephone, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Fax, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Email, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, NetAddress, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, ZipCode, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Address, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BankAccount, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BankAccountName, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, BankName, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, Comment, oBusinessUnitsDdo);
    SQL_SET_FIELD_BEFORE_VALUE(ssSql, ContactSysNos, oBusinessUnitsDdo);
    //因为Property需要取值运算，只能采用重新设置的方法。
    SQL_SET_PROPERTY_FIELD(ssSql, BusinessUnitsProperty, oBusinessUnitsDdo);

    // Last update.
    SQL_SET_TIME_FIELD_NOW_END(ssSql, RowModifyDate);
    // -----Update End.

    C2C_WW_LOG_DEBUG("sql:%s", ssSql.str().c_str());//debug

    DB_UPDATE(m_oStorage, ssSql, iRetCode, rCntlInfo, strMachineKey, strSource, dwSceneId);

    return iRetCode;
}

 /**
 *
 *   删除来往单位（逻辑）
 *
 */
int32_t CAccountDBOperator::DeleteBusinessUnits(
        const CCntlInfo& rCntlInfo,
        const std::string& strMachineKey,
        const std::string& strSource,
        uint32_t dwSceneId,
        uint32_t dwOption,
        uint64_t ddwBusinessUnitsSysNo,
        const std::string& strInReserve,
        std::string& strErrmsg,
        std::string& strOutReserve
)
{
    int32_t iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwKeyId = rCntlInfo.getOperatorUin();

    C2C_WW_LOG("CAccountDBOperator %s cmdID:%u dwEmployeeId:%u sDbRoleName:%s sTableBaseName:%s wUseSetId:%u", __FUNCTION__,
            rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS, wUseSetId);

    CONNECT_WITH_DALSET(m_oStorage, rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS, wUseSetId,
            rCntlInfo, strMachineKey, strSource, dwSceneId);

    std::stringstream ssSql;
    SQL_UPDATE_TABLE(ssSql, wUseSetId, dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS);
    SQL_SET_INT_FIELD_VALUE(ssSql, BusinessUnitsStatus, 0);
    SQL_WHERE_BEGIN(ssSql);
    SQL_WHERE_INT_PRIMARY_VALUE(ssSql, BusinessUnitsSysNo, ddwBusinessUnitsSysNo);

    C2C_WW_LOG_DEBUG("sql:%s", ssSql.str().c_str());//debug

    DB_UPDATE(m_oStorage, ssSql, iRetCode, rCntlInfo, strMachineKey, strSource, dwSceneId);

    return iRetCode;
}

 /**
 *
 *   根据分支机构ID批量获取分支机构信息
 *
 */
int32_t CAccountDBOperator::GetBusinessUnitsBySysNos(
     const CCntlInfo& rCntlInfo,
     const std::string& strMachineKey,
     const std::string& strSource,
     uint32_t dwSceneId,
     uint32_t dwOption,
     const std::set<uint64_t> & setBusinessUnitsSysNo,
     const std::string& strInReserve,
     std::string& strErrmsg,
     std::map<uint64_t,uint32_t> & mapErrorCode,
     std::map<uint64_t,std::string> & mapErrorMsg,
     std::map<uint64_t,erp::account::ddo::CBusinessUnitsDdo> & mapBusinessUnitsDdo,
     std::string& strOutReserve
    )
{

    if (setBusinessUnitsSysNo.size() <=0)
    {
        return 0;
    }

    int32_t iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwKeyId = rCntlInfo.getOperatorUin();

    C2C_WW_LOG("CAccountDBOperator %s cmdID:%u dwEmployeeId:%u sDbRoleName:%s sTableBaseName:%s wUseSetId:%u", __FUNCTION__,
            rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, DB_ROLE_NAME_ACCOUNT, wUseSetId);


    CONNECT_WITH_DALSET(m_oStorage, rCntlInfo.getCmdId(), rCntlInfo.getOperatorUin(), DB_ROLE_NAME_ACCOUNT,
                TABLE_NAME_BUSINESSUNITS, wUseSetId, rCntlInfo, strMachineKey, strSource, dwSceneId);

    std::stringstream ssSql;
    SQL_SELECT_TABLE(ssSql, wUseSetId, rCntlInfo.getOperatorUin(), DB_ROLE_NAME_ACCOUNT, DB_ROLE_NAME_ACCOUNT,
            "FBusinessUnitsSysNo,FBusinessUnitsType,FBusinessUnitsID,FFullName,FName,FPyCode,UNIX_TIMESTAMP(FCreateDate) as FCreateDate,UNIX_TIMESTAMP(FPayDueTime) as FPayDueTime,FDiscountRate,FPrePriceLevel,"
            "FTelephone,FFax,FEmail,FNetAddress,FZipCode,FAddress,FBankAccount,FBankAccountName,FParentSysNo,FClearingContactUnitSysNo,FAreaSysNo,"
            "FStaffSysNo,FBankName,FComment,FContactSysNos,FBusinessUnitsProperty,FBusinessUnitsStatus,FCreatorSysNo,UNIX_TIMESTAMP(FRowCreatDate) as FRowCreatDate,FModifierSysNo,UNIX_TIMESTAMP(FRowModifyDate) as FRowModifyDate");
    SQL_WHERE_BEGIN(ssSql);
    SQL_WHERE_FIELD_SET_VALUE(ssSql, BusinessUnitsSysNo, setBusinessUnitsSysNo);

    c2cent::storage::IResultSet& oRs=DB_SELECT(m_oStorage, ssSql);

    DB_SELECT_RS_CHECK(oRs, m_oStorage, ssSql, iRetCode, rCntlInfo, strMachineKey, strSource, dwSceneId);

    //循环取数据
    do{
        erp::account::ddo::CBusinessUnitsDdo obusinessUnitsDdo;

        RS_GET_INT_FIELD(oRs, BusinessUnitsSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsType, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, CreateDate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, PayDueTime, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, DiscountRate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, PrePriceLevel, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ParentSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ClearingContactUnitSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, AreaSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, StaffSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsProperty, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsStatus, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, CreatorSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ModifierSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, RowCreatDate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, RowModifyDate, obusinessUnitsDdo);

        RS_GET_STRING_FIELD(oRs, BusinessUnitsID, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, FullName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Name, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, PyCode, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Telephone, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Fax, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Email, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, NetAddress, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, ZipCode, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Address, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankAccount, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankAccountName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Comment, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, ContactSysNos, obusinessUnitsDdo);


        mapBusinessUnitsDdo[obusinessUnitsDdo.GetBusinessUnitsSysNo()] = obusinessUnitsDdo;
    }while(oRs.Next());
    oRs.Close();

    return iRetCode;
}

 /**
 *
 *   根据过滤条件查询来往单位列表信息
 *
 */
int32_t CAccountDBOperator::GetBusinessUnitsByFilter(
     const CCntlInfo& rCntlInfo,
     const std::string& strMachineKey,
     const std::string& strSource,
     uint32_t dwSceneId,
     uint32_t dwOption,
     const erp::account::ddo::CBusinessUnitsFilterDdo& oFilter,
     const std::string& strInReserve,
     std::string& strErrmsg,
     uint32_t& dwTotal,
     std::vector<erp::account::ddo::CBusinessUnitsDdo> & vecBusinessUnitsDdo,
     std::string& strOutReserve
    )
{
    int32_t iRetCode = 0;
    uint16_t wUseSetId = 0;
    uint32_t dwKeyId = rCntlInfo.getOperatorUin();


    CONNECT_WITH_DALSET(m_oStorage, rCntlInfo.getCmdId(), dwKeyId, DB_ROLE_NAME_ACCOUNT, TABLE_NAME_BUSINESSUNITS, wUseSetId,
            rCntlInfo, strMachineKey, strSource, dwSceneId);


    CONNECT_WITH_DALSET(m_oStorage, rCntlInfo.getCmdId(), rCntlInfo.getOperatorUin(), DB_ROLE_NAME_ACCOUNT,
                TABLE_NAME_BUSINESSUNITS, wUseSetId, rCntlInfo, strMachineKey, strSource, dwSceneId);

    std::stringstream ssSql;
    SQL_SELECT_TABLE(ssSql, wUseSetId, rCntlInfo.getOperatorUin(), DB_ROLE_NAME_ACCOUNT, DB_ROLE_NAME_ACCOUNT,
            "FBusinessUnitsSysNo,FBusinessUnitsType,FBusinessUnitsID,FFullName,FName,FPyCode,UNIX_TIMESTAMP(FCreateDate) as FCreateDate,UNIX_TIMESTAMP(FPayDueTime) as FPayDueTime,FDiscountRate,FPrePriceLevel,"
            "FTelephone,FFax,FEmail,FNetAddress,FZipCode,FAddress,FBankAccount,FBankAccountName,FParentSysNo,FClearingContactUnitSysNo,FAreaSysNo,"
            "FStaffSysNo,FBankName,FComment,FContactSysNos,FBusinessUnitsProperty,FBusinessUnitsStatus,FCreatorSysNo,UNIX_TIMESTAMP(FRowCreatDate) as FRowCreatDate,FModifierSysNo,UNIX_TIMESTAMP(FRowModifyDate) as FRowModifyDate");
    SQL_WHERE_BEGIN(ssSql);
    SQL_WHERE_FIELD_SET_VALUE(ssSql, ParentSysNo, oFilter.GetParentSysNo());
    SQL_WHERE_FIELD_SET_NAME(ssSql, BusinessUnitsStatus, oFilter, Status);
    SQL_WHERE_PROPERTY_FIELD_NAME(ssSql, BusinessUnitsProperty, oFilter, Property, oFilter.GetPropertyOption());

	ssSql<<" limit "<<(oFilter.GetPage()-1)*oFilter.GetPageSize()<<","<<oFilter.GetPageSize();
    c2cent::storage::IResultSet& oRs=DB_SELECT(m_oStorage, ssSql);

    DB_SELECT_RS_CHECK(oRs, m_oStorage, ssSql, iRetCode, rCntlInfo, strMachineKey, strSource, dwSceneId);

    //循环取数据
    do{
        erp::account::ddo::CBusinessUnitsDdo obusinessUnitsDdo;

        RS_GET_INT_FIELD(oRs, BusinessUnitsSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsType, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, CreateDate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, PayDueTime, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, DiscountRate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, PrePriceLevel, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ParentSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ClearingContactUnitSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, AreaSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, StaffSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsProperty, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, BusinessUnitsStatus, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, CreatorSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, ModifierSysNo, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, RowCreatDate, obusinessUnitsDdo);
        RS_GET_INT_FIELD(oRs, RowModifyDate, obusinessUnitsDdo);

        RS_GET_STRING_FIELD(oRs, BusinessUnitsID, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, FullName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Name, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, PyCode, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Telephone, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Fax, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Email, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, NetAddress, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, ZipCode, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Address, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankAccount, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankAccountName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, BankName, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, Comment, obusinessUnitsDdo);
        RS_GET_STRING_FIELD(oRs, ContactSysNos, obusinessUnitsDdo);

        vecBusinessUnitsDdo.push_back(obusinessUnitsDdo);
    }while(oRs.Next());
    oRs.Close();

    return iRetCode;
}
